package cn.micro.eye.model.query;

import cn.micro.eye.commons.exception.MicroBadRequestException;
import cn.micro.eye.type.ClientCategoryEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 账号登录
 *
 * @author lry
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class AccountLogin implements Serializable {

    private String openId;
    private String password;
    private String randomStr;
    /**
     * {@link ClientCategoryEnum}
     */
    private Integer category;

    public void validate() {
        if (StringUtils.isBlank(openId)) {
            throw new MicroBadRequestException("账号不能为空");
        }
        if (StringUtils.isBlank(password)) {
            throw new MicroBadRequestException("密码不能为空");
        }
        if (category == null) {
            throw new MicroBadRequestException("客户端类型不能为空");
        }
        if (!ClientCategoryEnum.GROUP.contains(category)) {
            throw new MicroBadRequestException("非法客户端类型");
        }
    }

}
